
import { ref, watch, reactive, getCurrentInstance } from "vue"
import { Plus } from '@element-plus/icons-vue'
import request from '@/utils/request'
import statusComp from './component/statusComp'
import $button from '@/button'

export function OrderTemplateApi() {
    return request({
        url: "/order/import/template",
        method: "GET",
    });
}
// 确认打款
export function payConfirmApi(dataRequest) {
    return request({
        url: "/order/system/pay/confirm",
        method: "PUT",
        data: dataRequest
    });
}
// 申请开票
export function invoicingApi(dataRequest) {
    return request({
        url: "/invoice",
        method: "POST",
        data: dataRequest
    });
}
// 同意退款
export function refundAgreeApi(dataRequest) {
    return request({
        url: "order/refund/agree",
        method: "PUT",
        data: dataRequest
    });
}
// 申请退款
export function refundPayoutApi(dataRequest) {
    return request({
        url: "/order/refund/payout",
        method: "PUT",
        data: dataRequest
    });
}
export const tableItem = reactive({
    select: false,//多选框
    loading: false,
    index: !true,//顺序
    expandAll: false,//树形默认展开
    tree: true,//树形
    align: 'center',
    column: [
        {
            label: '订单号',
            prop: 'num',
        },
        {
            label: '商家名称',
            prop: 'sale',
        },
        {
            label: '学员数量',
            prop: 'itemAmount',
        },
        {
            label: '订单来源',
            htmlContent: row => {
                let result = '小程序创建'
                row.sourceTypeCode == 'system' ? result = '系统导入' : ''
                return `<span>${result}</span> `
            },

        },
        {
            label: '应付金额（元）',
            prop: 'price',
        },
        {
            label: '订单状态',
            component: statusComp,
            param: 'statusCode',
            // htmlContent: row => {
            //     let result = ''
            //     switch (row.payStatusCode) {
            //         case 'pending': result = '待付款'; break;
            //         case 'done': result = '已付款 '; break;
            //         case 'cancel': result = '已取消'; break;
            //         default: ; break;
            //     }
            //     return `<span>${result}</span> `
            // },
        },
        {
            label: '退款状态',
            component: statusComp,
            param: 'refundStatusCode',
            // htmlContent: row => {
            //     let result = ''
            //     let statusStyle = ''
            //     switch (row.refundStatusCode) {
            //         case 'refunding': result = '退款中'; statusStyle = 'labelIcon-danger'; break;
            //         case 'success': result = '退款成功'; statusStyle = 'labelIcon-primary';break;
            //         case 'failed': result = '退款失败'; statusStyle = 'labelIcon-danger';break;
            //         case 'cancel': result = '已取消'; statusStyle = 'labelIcon-danger';break;
            //         default: ; break;
            //     }
            //     return `<span :class="statusStyle">${result}</span> `
            // },
        },
        {
            label: '支付方式',
            tipContent: '线下支付：除小程序下单并微信支付外，都算作线下支付',
            htmlContent: row => {
                let result = ''
                switch (row.payMethodCode) {
                    case 'wechat': result = '微信支付'; break;
                    case 'alipay': result = '支付宝支付'; break;
                    case 'offline': result = '线下支付'; break;
                    default: ; break;
                }
                return `<span>${result}</span> `
            },
        },
        {
            label: '支付时间',
            prop: 'payTime',
        },
        {
            label: '所属销售',
            prop: 'saleRootName',
            htmlContent: row => {
                let saleRoot = row.saleRootName + '(' + row.saleRootNum + ')'
                return `<span>${saleRoot}</span> `
            },
        },
        {
            label: '创建时间',
            prop: 'createTime',
        },
        // {
        //     label: '打款状态',
        //     component: statusComp,
        //     param: 'receiveStatusCode',
        //     // htmlContent: row => {
        //     //     let result = '待打款 '
        //     //     switch (row.receiveStatusCode) {
        //     //         case 'pending': result = '待打款 '; break;
        //     //         case 'done': result = '已打款 '; break;
        //     //         case 'non': result = '已取消 '; break;
        //     //         default: ; break;
        //     //     }
        //     //     return `<span>${result}</span> `
        //     // },
        // },
        {
            label: '操作',
            prop: 'action',
        }
    ],
    pageInfo: {
        request: {
            "num": "", //身份标识
            "sale": "", //销售姓名或者编号
            "sourceTypeCode": "", //订单来源："app"-小程序创建 "system"-系统导入
            "statusCode": "", //paying-支付中，paidAuditing-支付审核中，paid-已支付，cancel-已取消
            // "receiveStatusCode": "", //打款状态："pending"-待打款 "done"-已打款
            "createTimeStart": "",
            "createTimeEnd": "",
            "pageDomain": {
                "pageNum": '1',//分页页面数
                "pageSize": '10',//分页页面数据大小
                "orderByColumn": "",//搜索参数
                "isAsc": "",//搜索参数
                "reasonable": ""//搜索参数
            }
        },
        url: '/order/paging',//分页路由，不传的话需要传入自定义的分页函数paging 传入时定义的分页函数paging会失效
        // 分页函数paging
        paging: function () {

        }
    },
    tableData: {
        total: '',//分页总计
        // 分页数据
        data: []
    },
    // 操作栏按钮
    btnArray: []
})
export const operationItem = reactive({
    defaultSearch: true,//默认搜索按钮
    SearchText: '查询',
    defaultRefresh: false,//默认重置按钮
    customTableHeader: false,//
    SearchItem: [
        {
            code: "num",
            name: "订单号",
            type: "input",
        },
        {
            code: "sale",
            name: "商家名称/编号",
            type: "input",
        },
        {
            code: "sourceTypeCode",
            name: "订单来源",
            type: "select",
            options: [
                {
                    value: 'app',
                    label: '小程序创建'
                },
                {
                    value: 'system',
                    label: '系统导入'
                },
            ]
        },
        {
            code: "statusCode",
            name: "订单状态",
            type: "select",
            options: [
                {
                    value: 'paying',
                    label: '待支付'
                },
                {
                    value: 'payAuditing',
                    label: '审核中'
                },
                {
                    value: 'paid',
                    label: '已付款'
                },
                {
                    value: 'cancel',
                    label: '已取消'
                },
            ]
        },
        // {
        //     code: "receiveStatusCode",
        //     name: "打款状态",
        //     type: "select",
        //     options: [
        //         {
        //             value: 'pending',
        //             label: '待打款'
        //         },
        //         {
        //             value: 'done',
        //             label: '已打款'
        //         },
        //     ]
        // },
        {
            code: ["createDateStart",
                "createDateEnd",], //
            startName: "创建日期", //默认是开始时间 type为 daterange生效
            rangeName: "", //默认是至 type为 daterange生效
            endName: "创建日期", //默认是结束时间 type为 daterange生效
            valueFormat: "", //默认是YYYY-MM-DD
            placeholder: "请选择日期", //默认是请选择日期type为date生效
            type: "daterange", //daterange或date
        },
    ],
    menuArray: [
        {
            show: true,
            type: 'primary',
            text: '导入名单',
            hasPermi: [$button.courseorderimport || null],
            icon: Plus,
            customParameters: 'add',//自定义函数参数
            handle: () => {
                console.log('handle')
            }
        },
    ]
})
